#ifndef __PLAY_H__
#define __PLAY_H__

#include <linux/soundcard.h>

#define INSTRUMENT_N 3
#define PIANO 0     //钢琴
#define ACCORDION 1 //手风琴
#define violin 3    //小提琴
//TODO add more instruments

#define PLAY_DEVICE "/dev/dsp"
#define SAMPLING_RATE 44100
#define DATA_FMT AFMT_U8
#define CHANNEL_NUM 1

class play_t
{
public:
    play_t();
    play_t(const play_t &) = delete;
    play_t(play_t &&) = delete;
    ~play_t();

public:
    void operator()(int instrument,    // instrument - piano, violin
                    int freq_index,    // freq_list[freq_index] --> frequency
                    int time_ms,       // time duration: millisecends
                    int volume = 100); // volume: 0 ~ 100(defalt)

    void set_freq_list(double *freq_list);

    int play_buf(void *data_buf_, size_t buf_size);

private:
    int m_play_device_fd;
    double *m_freq_list;
    void (*play_instruments[INSTRUMENT_N])(double frequency, double time, double AM);
};

extern play_t play;

void set_freq_list(double *freq_list);

#endif // __PLAY_H__
